package cn.edu.hit.education.listener;

import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.ViewerDropAdapter;
import org.eclipse.swt.dnd.TransferData;

import cn.edu.hit.education.view.CourseScheduleView;

public class CourseDropTargetListener extends ViewerDropAdapter {
	private CourseScheduleView view;
	/**
	 * @param parentComposite
	 *            - the composite that holds all pictures
	 * @param target
	 *            - the drop target
	 */
	public CourseDropTargetListener(TableViewer tableViewer,CourseScheduleView view) {
		super(tableViewer);
		this.view = view;
	}

	@Override
	public boolean performDrop(Object data) {
		String nodeId = (String)data;
		int id = Integer.parseInt(nodeId);
		if(id > 0){
			view.addNewCourse(id);
		}
		return true;
	}

	@Override
	public boolean validateDrop(Object target, int operation,
			TransferData transferType) {
		return true;
	}
}
